package br.com.gecandango.service.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import br.com.gecandango.beans.Refeicao;
import br.com.gecandango.service.RefeicaoService;

public class RefeicaoServiceImpl extends HibernateDaoSupport implements
	RefeicaoService {
	
	public Refeicao save(Refeicao bean) {
		Long id;
		if(bean.getId()==null){
			id =  (Long)getHibernateTemplate().save(bean);
			bean.setId(id);
		} else {
			getHibernateTemplate().saveOrUpdate(bean);
		}
		return bean;
	}
	public List<Refeicao> listRefeicoes() {
		return getHibernateTemplate().find("from Refeicao");
	}
	public Refeicao findRefeicao(Long id) {
		List<Refeicao> e = (List<Refeicao>)getHibernateTemplate().find("from Refeicao where id=?", id);
		return e.get(0);
	}
	
	public void delete(Refeicao bean) {
		getHibernateTemplate().delete(bean);
	}
	
}
